/*
 * types.h
 *
 * Copyright (C) 2015 - kali
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef LAMBDA_H
#define LAMBDA_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <ctype.h>
#define lmd_catom(x) ((atom *) x)


typedef enum {
	TCONS, TINT, TCHAR, TFUN, TSTRING, TSYM, TBOOL, TAX, TMAC, TCONT
} atom;


extern atom sect, secf;
extern atom *t, *f;

/*
typedef struct acont {
	atom t;
	char *stack, *respt;
	int size;
	jmp_buf registers;
} acont;
*/


typedef struct acons {
	atom t, *car, *cdr;
} acons;


typedef struct aint {
	atom t;
	int i;
} aint;


typedef struct achar {
	atom t;
	char c;
} achar;


typedef struct astring {
	atom t;
	char *s;
} astring;



typedef struct asym {
	atom t;
	char *s;
} asym;


typedef struct nspace {
	struct nspace *next;
	asym *name;
	atom *link;
} nspace;


typedef struct aax {
	atom t;
	atom *(*primitive)(acons*, nspace*);
} aax;



typedef struct afun {
	atom t;// = tfun;
	nspace *n;
	atom *args;
	acons *body;
} afun;

atom *lmd_newbool(int val); 
atom *lmd_newcons(atom *car, atom *cdr);
acons *lmd_ccons(atom *x);
atom *lmd_newint(int i);
aint *lmd_cint(atom *x);
atom *lmd_newchar(char c);
achar *lmd_cchar(atom *x);
atom *lmd_newstring(char *s);
astring *lmd_cstring(atom *x);
atom *lmd_newsym(char *s);
asym *lmd_csym(atom *x);
nspace *lmd_bind(nspace *head, asym *name, atom *link) ;
atom *lmd_newax(atom *(*a)(acons*, nspace*));
aax *lmd_cax(atom *x);
atom *lmd_newfun(atom *args, acons *body, nspace *n);
afun *lmd_cfun(atom *x);
int lmd_eq(atom *a, atom *b);
//void lmd_printns (nspace *n);
void lmd_print (atom *x);
#endif
